package binaryTree;

import utils.binaryTreeUtil.TreeNode;

public class sortedArrayToBST {
    //想着每次取中间，然后放
    
    public TreeNode sortedArrayToBST(int[] nums) {
        
        TreeNode lnode = sort(nums, 0, nums.length-1);
        // TreeNode rnode = sort(nums, mid+1, nums.length-1, node);
        // node.left=lnode;
        return lnode;
    }
    public TreeNode sort(int[] nums,int start,int end){
        if (start>end) {
            return null;
        }

        int mid=(start+end)/2;
        TreeNode node = new TreeNode(nums[mid]);
        TreeNode lsort = sort(nums, start, mid-1);
        TreeNode rsort = sort(nums, mid+1, end);
        node.left=lsort;
        node.right=rsort;
        return node;
    }
    public static void main(String[] args) {
        
    }
}
